package com.eunion.core.common.jpa.impl;

import java.util.List;

import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

import com.eunion.core.common.view.QueryView;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonView;

/**
 * 在属性上添加JsonView开放可见性。
 *
 * @author Hall Wong
 *
 * @param <Bean>
 */
@JsonPropertyOrder({ "totalCount", "totalPages", "pageNo", "pageSize", "first", "last", "hasPrevious", "hasNext",
        "content" })
public class SimplePage<Bean> extends PageImpl<Bean> {

    private static final long serialVersionUID = 1L;

    public SimplePage(List<Bean> content) {
        super(content);
    }

    public SimplePage(List<Bean> content, Pageable pageable, long total) {
        super(content, pageable, total);
    }

    @JsonView(QueryView.class)
    @Override
    public List<Bean> getContent() {
        return super.getContent();
    }

    @JsonView(QueryView.class)
    @Override
    public int getTotalPages() {
        return super.getTotalPages();
    }

    @JsonProperty("totalCount")
    @JsonView(QueryView.class)
    @Override
    public long getTotalElements() {
        return super.getTotalElements();
    }

    @JsonView(QueryView.class)
    @Override
    public boolean isFirst() {
        return super.isFirst();
    }

    @JsonView(QueryView.class)
    @Override
    public boolean isLast() {
        return super.isLast();
    }

    @JsonView(QueryView.class)
    @Override
    public boolean hasPrevious() {
        return super.hasPrevious();
    }

    @JsonView(QueryView.class)
    @Override
    public boolean hasNext() {
        return super.hasNext();
    }

    @JsonProperty("pageNo")
    @JsonView(QueryView.class)
    @Override
    public int getNumber() {
        return super.getNumber();
    }

    @JsonProperty("pageSize")
    @JsonView(QueryView.class)
    @Override
    public int getSize() {
        return super.getSize();
    }

}
